#!/usr/bin/ruby

require 'compiler/ui'
require 'compiler/token_position'
require 'compiler/token'
require 'compiler/lexical_analyzer'
require 'getoptlong'

def usage
  UI.log "Usage: ruby pamc.rb [OPTIONS] FILE"
end

$params = { :ignore_lexical_error => false }

opts=GetoptLong.new(
  ['-I', GetoptLong::NO_ARGUMENT]
)

opts.each do |opt, arg|
  case opt
    when '-I'
      $params[:ignore_lexical_error] = true
  end
end

$file = ARGV.shift
if $file.nil?
  usage
  exit
end


begin
  errors = []
  la = LexicalAnalyzer.new($file,errors)
  la.run

  if errors.size > 0 and not $params[:ignore_lexical_error]
    errors.each { |e| UI.log e }
  else
    la.dump
  end
#rescue
#  UI.log $!
end
